'use strict';

const Service = require('egg').Service;

const moment = require('moment');

class MusicService extends Service {
    //添加歌曲
    async addmusic(name,pic,singer,isup) {
        await this.app.mysql.query('insert into musiclist (name,pic,singer,isup) values (?,?,?,?)',[name,pic,singer,isup])
    }

    //查询歌曲
    async querymusic(startIndex,limit){
        return await this.app.mysql.query(`select * from musiclist limit ${startIndex},${limit}`)
    }

    //查询总数
    async total(){
        return await this.app.mysql.query('select count(*) from musiclist');
    }

    //修改歌曲
    async updatemusic(name,pic,singer,isup,id){
        return await this.app.mysql.query('update musiclist set name=?,pic=?,singer=?,isup=? where id=?',[name,pic,singer,isup,id])
    }

    //删除歌曲
    async deletemusic(id){
        await this.app.mysql.query('delete from musiclist where id=?',[id])
    }

}

module.exports = MusicService;
